﻿using Appliaction.Dto.Inv;
using Appliaction.IAppServices.Inv;
using AutoMapper;
using Domain.Entitys.Inv;
using Domain.IRepositorys.Inv;
using EFCore.Repositorys.Inv;
using Microsoft.AspNetCore.Mvc;
using static StackExchange.Redis.Role;

namespace API.Controllers.Inv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class Inv_SampController : Controller
    {
        private readonly IMapper _mapper;
        private readonly IInv_SampServices  inv_SampServices;


        public Inv_SampController(IInv_SampServices inv_SampServices, IMapper mapper)
        {
            this.inv_SampServices = inv_SampServices;
            _mapper = mapper;
        }


        /// <summary>
        /// 根据编号查询主表
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<JsonResult> Inv_samp_SelectCode(string Samp_code)
        {
            var resukt = await inv_SampServices.Inv_Qty_SelectCode(Samp_code);
            return new JsonResult(resukt);
        }

        /// <summary>
        /// 根据编号查询明细表
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<JsonResult> Inv_samp_SelectDetail(string Samp_code)
        {
          var resukt=await inv_SampServices.Inv_Qty_SelectDetail(Samp_code);
            return new JsonResult(resukt);
        }
        /// <summary>
        /// 查询数量
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <param name="Samp_type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<int> Inv_Samp_selectCount(string ? Samp_code, string? Samp_type)
        {
            return inv_SampServices.Inv_Samp_selectCount(Samp_code, Samp_type);
        }
        /// <summary>
        /// 查询分页
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <param name="Samp_type"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public JsonResult Inv_Samp_selectFY(string ? Samp_code, string ? Samp_type, int currentPage, int pageSize)
        {
           return new JsonResult(inv_SampServices.Inv_Samp_selectFY(Samp_code, Samp_type, currentPage, pageSize));
        }


        /// <summary>
        /// 修改审核状态
        /// </summary>
        /// <param name="inv_SampUpdateDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_samp_audit_statusUpdate(Inv_SampUpdateDto inv_SampUpdateDto)
        {
           return inv_SampServices.Inv_samp_audit_statusUpdate(inv_SampUpdateDto);
        }


        /// <summary>
        /// 删除抽检单
        /// </summary>
        /// <param name="Samp_id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_samp_Delete(int Samp_id)
        {
           return inv_SampServices.Inv_Qty_Delete(Samp_id);
        }



        /// <summary>
        /// 添加抽检单
        /// </summary>
        /// <param name="inv_SampAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_Samp_Insert(Inv_SampAddDto inv_SampAddDto)
        {
            return inv_SampServices.Inv_Samp_Insert(inv_SampAddDto);
        }

        /// <summary>
        /// 添加抽检单详情
        /// </summary>
        /// <param name="inv_prodInfo"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<IActionResult> Inv_prodInfo_Insert(List<Inv_ProdInfoAddDto> inv_prodInfoDto)
        {
            try
            { 
                int result=await inv_SampServices.Inv_prodInfo_Insert(inv_prodInfoDto);
                return Ok(result);

            }catch (Exception ex)
            {
                return new JsonResult(ex.Message);
            }
        }
        /// <summary>
        /// 编号查询ID
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<int> Inv_sampt_selectId(string Samp_code)
        {
            return inv_SampServices.Inv_sampt_selectId(Samp_code);
        }

        /// <summary>
        /// 修改抽检单
        /// </summary>
        /// <param name="inv_SampUpdateMerage"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<JsonResult> Inv_Smap_Update([FromBody]Inv_SampUpdateMerage inv_SampUpdateMerage)
        {
           return new JsonResult(await inv_SampServices.Inv_Smap_Update(inv_SampUpdateMerage));
        }



        /// <summary>
        /// 查询抽检单--出库单--查询
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Inv_Select_SampSelect(string ? code, int currentPage, int pageSize)
        {

           return new JsonResult(inv_SampServices.Inv_Select_SampSelect(code, currentPage, pageSize));
        }

        /// <summary>
        /// 查询抽检单--出库单--查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Inv_Select_SmapSelect_Count(string ? code)
        {

            return inv_SampServices.Inv_Select_SmapSelect_Count(code);
        }

        /// 查询抽检单--出库单--查询详情
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Inv_Select_Inv_prodInfo(string code)
        {

            return new JsonResult(inv_SampServices.Inv_Select_Inv_prodInfo(code));
        }



        /// <summary>
        /// 出库完成之后,审核完毕--修改抽检单的字段
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public Task<int> Inv_Samp_Outbound_update(int id)
        {

           return inv_SampServices.Inv_Samp_Outbound_update(id);
        }

    }
}
